package cj.web.marriageSC.dao;
/*
 *  
 *  
*/
import java.util.List;
import java.util.Map;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.marriageSC.domain.SCCategory;

/**
 * 
 * @author 
 *
 */
@DAO
public interface SCCategoryDAO{
	
    @SQL("select * from SCCategory where id=:1")
    SCCategory queryById(int id);
    
    @SQL("select id,name from SCCategory where deleteFlag=1 order by parentId,sort")
    List<Map> queryAll();
    
    @SQL("select * from SCCategory where deleteFlag=1")
    List<SCCategory> queryAllObjs();
    
    @SQL("INSERT INTO SCCategory (parentId,name,image,sort,deleteFlag,createUser,createAt,updateUser,updateAt) VALUES (:t.parentId,:t.name,:t.image,:t.sort,:t.deleteFlag,:t.createUser,NOW(),:t.updateUser,NOW())")
    void create(@SQLParam("t") SCCategory sCCategory);
	
	@SQL("UPDATE SCCategory SET name=:t.name,image=:t.image,sort=:t.sort,updateUser=:t.updateUser,updateAt=NOW() WHERE id=:t.id")
    void update(@SQLParam("t") SCCategory sCCategory);
    
    @SQL("UPDATE SCCategory SET deleteFlag=0,updateUser=:t.updateUser,updateAt=NOW() WHERE id=:t.id")
    void deleteById(@SQLParam("t") SCCategory sCCategory);

    @SQL("select a.id,a.name,a.sort,b.name as parentName from SCCategory a LEFT JOIN SCCategory b on a.parentId=b.id where a.deleteFlag=1 #if(:t.name!=''){ and a.name like '%##(:t.name)%' } order by a.parentId,a.sort limit :t.start,:t.length")
	List<Map> queryByName(@SQLParam("t") SCCategory sCCategory);

    @SQL("select count(a.id) from SCCategory a LEFT JOIN SCCategory b on a.parentId=b.id where a.deleteFlag=1 #if(:t.name!=''){ and a.name like '%##(:t.name)%' } ")
	int sizeByName(@SQLParam("t")SCCategory category);

}